#!/usr/bin/env python
# -*- coding:utf-8 -*-

import yaml
import os
from util.getlog import get_log
from configs.globalVariables import logger
'''
【功能】：向Yaml写入数据
【入参】：写入内容，文件名(包含路径)
【返回值】：无
'''

def writeYaml(data,yamlPath):
    try:
        with open(yamlPath, 'w', encoding='utf-8') as f:
            yaml.dump(data, f,encoding='utf-8',allow_unicode=True) #生成yaml文件并写入值
    except Exception as e:
        logger.error("写入Yaml文件出错了~ %s" % e)

if __name__ == "__main__":
    # 获取配置文件路径
    curPath = os.path.abspath(os.path.dirname(__file__))
    yamlPath = os.path.abspath(os.path.dirname(curPath) + os.path.sep + "configs/access_token.yml")
    access_token = {'access_token':'dfksakljfalskd'}
    writeContent = writeYaml(access_token,yamlPath)


'''
os.path.dirname(__file__)： 获取文件所在目录的完整路径；
os.path.abspath(path): 返回绝对路径
'''